package com.hyfrogx.modules.manage.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hyfrogx.common.utils.ShiroUtils;
import com.hyfrogx.modules.manage.dao.HyGiveConfigDao;
import com.hyfrogx.modules.manage.entity.HyGiveConfigEntity;
import com.hyfrogx.modules.manage.form.parameter.GiveConfigForm;
import com.hyfrogx.modules.manage.form.parameter.GiveConfigVo;
import com.hyfrogx.modules.manage.service.HyGiveConfigService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @version 1.0.0
 * @Author: lfh
 * @Date: 2019/9/24 10:30
 * @Company 汉咏科技
 */
@Service
public class HyGiveConfigServiceImpl extends ServiceImpl<HyGiveConfigDao, HyGiveConfigEntity> implements HyGiveConfigService {

    @Override
    public GiveConfigVo getGiveOne() {
        //转赠参数设置唯一，且主键id为1
        HyGiveConfigEntity hyGiveConfigEntity = this.getOne(new QueryWrapper<HyGiveConfigEntity>().eq("id",1),true);
        return BeanUtil.toBean(hyGiveConfigEntity, GiveConfigVo.class);

    }

    @Override
    public Boolean updateGiveConfig(GiveConfigForm giveConfigForm) {
        //将转赠参数表单转换成转赠实体类
        HyGiveConfigEntity hyGiveConfigEntity = BeanUtil.toBean(giveConfigForm,HyGiveConfigEntity.class);
        //设置更改时间和更改者id
        hyGiveConfigEntity.setUpdatetime(new Date());
        Long userid = ShiroUtils.getUserEntity().getUserId();
        hyGiveConfigEntity.setUserId(userid);
        return updateById(hyGiveConfigEntity);
    }
}
